﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Dao.CommonDao;
using CSP.DataAccess;
using CSP.Model.CSP;

namespace CSP.Dao.ObjectDaos.CSP
{
    public class ClassTypeDao : CSPCommonDao, IClassTypeDao
    {
        public ClassTypeDao(CSPContext context, bool isTransaction = false)
            : base(context, isTransaction)
        {

        }

        public ICollection<ClassType> FindAll()
        {
            var result = _context.ClassTypes;
            if (result.Count() != 0)
            {
                return result.ToArray();
            }
            else
            {
                return null;
            }
        }

        public ClassType GetDataById(int id)
        {
            throw new NotImplementedException();
        }

        public ICollection<ClassType> GeDatatByIds(int[] Ids)
        {
            throw new NotImplementedException();
        }

        public void Add(ClassType obj)
        {
            _context.ClassTypes.Add(obj);
            _context.SaveChanges();
        }

        public void Update(ClassType obj)
        {
            _context.SaveChanges();
        }

        public ClassType DeleteById(int id)
        {
            ClassType classType = _context.ClassTypes.FirstOrDefault(c => c.Id == id);

            if (classType != null)
            {
                _context.ClassTypes.Remove(classType);
                _context.SaveChanges();
            }

            return classType;
        }
    }
}
